<template> 
  <div class="app-container">
      <div class="ces-main">
        <div ref="headRef">
        <el-row>
  <el-col :span="18"><div class="grid-content bg-purple"></div><Search-Form 
          ref="form"
          size='mini'
          labelWidth = '50px' 
          align="left"
          :searchData = 'Search'
           :tableCols = 'tableCols'
          :searchHandle="searchHandle"
          @handleEnter="refresh"></Search-Form ></el-col>
  <el-col :span="6"><div class="grid-content bg-purple-light">
    <v-GetToolBar align="right" :key="MenuCode" :MenuCode='MenuCode'  
          :IsfunEdit='IsfunEdit'
          :Isfunfail='Isfunfail'
          @handeAdd='handeAdd'
          @handleEdit='handleEdit'
          @OpenFindForm='getDataList'
          @handlexportData='handlexportData'
          @IsfunEdit='handleIsfunEdit'
          @IsfunDelete='handleIsfunfail'
            @handleclose='handleclose'
          ></v-GetToolBar>
    
        </div></el-col>
</el-row>

</div>

      
        <ces-table 
          size='mini'
          
          ref="tableData"
          :isSelection='false'
          :isIndex='true'
          :isSearch='true'
          :isHandle='false'
          :IsfunEdit='IsfunEdit'
          :Isfunfail='Isfunfail'
          :tableData='tableData' 
          :tableCols='tableCols' 
          :ToolBarheight='ToolBarheight'
          :Search='Search'
          @refresh="refresh"
          @handleEdit='handleEdit'
          @handleDelete="delData"
          @handrowclick="handrowclick"
          >
          </ces-table>
      
      
        
       
    
  
         
          </div>
  
   <!--搜索弹框-->
      <el-dialog
        title="搜索"
        :visible.sync="SearchDialog"
        custom-class="dialogClass"
        class="searchDialog"
        center
        ref="searchDialog"
        :modal="false"
        :close-on-click-modal="true"
      >
        <el-form :model="Search" label-width="90px" ref="searchForm">
         
         <Search-Form
         :frame="true" 
          ref="form"
          size='mini'
          labelWidth = '50px' 
          :searchData = 'Search'
           :tableCols = 'tableCols'
          :searchHandle="searchHandle"
          @handleEnter="refresh"></Search-Form >
        </el-form>
        <div
          slot="footer"
          :style="{ 'margin-buttom': 0 == 0 ? DialogBtnMargin : DialogBtnMargin }"
        >
          <el-button @click="reform()">重置</el-button>
          <el-button type="primary" @click="refresh()">确 定</el-button>
        </div>
      </el-dialog>


      <el-dialog
    v-if="dialogVisible"
    :visible.sync="dialogVisible"
    width="800px"
    top="20px"
     
  >
<el-form :model="name" label-width="80px"  label-position="right">
 <el-tabs type="border-card">
      <el-tab-pane label="">
    <el-form :model="FormData" label-width="90px" ref="MianForm">
     <Mian-Form 
      ref="form"
      :billIDName='billIDName' 
      labelWidth = '100px' 
      :FormData = 'FormData'
      :tableCols = 'tableCols'
      :StepSN = '0'
      :searchHandle="searchHandle"></Mian-Form >
    </el-form>
      </el-tab-pane>
<div style="float:right ">

<el-button type="primary" @click="handleOpenClose()">关闭</el-button>
      <el-button type="primary" @click="handleSave()">保存</el-button>

</div>
     
</el-tabs>
    
</el-form>
   
  </el-dialog>
  
  
  </div>
  </template>
  
  <script>
  
  
  //引入组件

  import cesTable from "../Common//ComVxeTable.vue";
  import SearchForm from "../Common//Search.vue";
  import MianForm from "../Common//form.vue";
  
  import { funDownload,funDownloadv1,GetTableColsData} from "@/api/Common";
  import { DeleteForm,CloseForm,UpdateForm,getfunDownload } from '@/api/CommonPage/CommonPage'; //更改
  import { getDataList} from '@/api/APSscheduling/APS';
  import vGetToolBar from "../Common/GetToolBar";
  
  export default {
    name:"CommonPageVxe",
      data(){
           //表单查询一般分为input，下拉框，和日期，下面是下拉框时的设置下拉信息的情况，我的项目没有用到，但是留着方便看
        
          return {
          MenuCode: "",
          tableData:[],//表格数据
          tableCols:[],//表格列数据
          FormData:[],//表格数据
          searchHandle:[],
          billID:"",
          billIDName:"",
          IsfunEdit:false,
          Isfunfail:false,
          IsFieldText:0,
          Search: {
          // 查询条件
          total: 0, // 总记录数
          pageSize: 100, // 一页显示的记录数
          page: 1, // /当前页码
          RNO: "006", // 表编号  根据Controller中对应的表编号 //更改
          InterID:"1578",
          jsWhere: "", // 自定义条件
          Download:"",
          
          // Status: 0,
          //   BillState: "BillStateALL",
         
        },
        ToolBarheight:165,
         cities: [
            {
            value: "ALL",
            label: "ALL",
          },
          {
            value: "0",
            label: "草稿",
          },
          {
            value: "1",
            label: "审核中",
          },
          {
            value: "2",
            label: "结案",
          },
          {
            value: "3",
            label: "作废",
          },
        ],  BillStatecities: [
            {
            value: "BillStateALL",
            label: "ALL",
          },
          {
            value: "0",
            label: "未完成",
          },
          {
            value: "2",
            label: "已完成",
          }],
         SearchDialog: false,
           DialogBtnMargin: 0,
           dialogVisible: false,
            
          }
      },
  
     components:{ //引入组件后注册组件
      cesTable, 
       vGetToolBar,
       SearchForm,
       MianForm
     }, created() {
    
     },
     mounted(){
      
     
 debugger
      this.InterID = this.$route.query.InterID.replace("Page","");
      var InterData=this.InterID.split('-');
      this.InterID=InterData[1];
      this.MenuCode=InterData[0];
      this.Search.InterID=this.InterID;
        this.Search.RNO=this.InterID;
   
       
      
       
      this.getDataList()
     
     },
      methods:{
           //搜索重置
      refresh() {
        this.getDataList();
      },
       reform() {
         this.Search = {
          // 查询条件
          // total: 0, // 总记录数
          pageSize: 13, // 一页显示的记录数
          page: 1, // /当前页码
          RNO: "006", // 表编号  根据Controller中对应的表编号 //更改
          InterID:"1578",
          jsWhere: "", // 自定义条件
          Download:"",
          IsFieldText:'0'
          //   Status: 0,
          //   BillState: "BillStateALL",
        };
        this.Search.InterID=this.InterID;
        this.Search.RNO=this.InterID;
         this.getDataList();
      },
          async getDataList() {
           
           
          
          const res = await getDataList({ data: JSON.stringify(this.Search) });
          
          // this.tableCols=[];
        debugger


  //加载列头数据 
        
if(res.IsFieldText=='0')
{
  this.tableCols=res.data1;
  this.Search.IsFieldText='1'//已加载数据，不再加载

}
        

          this.tableData = res.data.Table;
         //将data 中的数据放到DataList中
         this.Search.total = res.data.Table1[0].RecordCount;

          setTimeout(() => {
      this.setHeight();
    
    }, 1000);
      
      },setHeight() {
        
        this.ToolBarheight = this.$refs.headRef.offsetHeight+130;
        
     
    },OpenFindForm() {
        //打开搜索框
        this.SearchDialog = true;
        //计算外边距
        console.log(this.$refs.searchDialog.offsetHeight);
        this.DialogBtnMargin = this.$refs.searchDialog.offsetHeight - 40;
      },async handlexportData() {
        this.Search.Download="1";
        const res = await getfunDownload({ data: JSON.stringify(this.Search) });
        this.Search.Download="0";
        funDownloadv1(res); //更改
      }, handleIsfunEdit() {
        this.IsfunEdit=true;
      }, handleIsfunfail() {
         this.Isfunfail=true;
      },async handeAdd() {
        // 新建
  

  const result = await UpdateForm({ IsPostBack:false,InterID:this.InterID});
   this.FormData=result.data1.Table[0];
   this.billIDName=result.billIDName;
   this.dialogType = 'edit'
      this.dialogVisible = true
      this.checkStrictly = true
    
      this.$nextTick(() => {
        const routes = this.generateRoutes(this.EditObj.routes)
        this.$refs.tree.setCheckedNodes(this.generateArr(routes))
        // set checked state of a node not affects its father and child nodes
        this.checkStrictly = false

      })
      this.getDataList();

        // let routeUrl = this.$router.push({
        //   path: "/MesPieceWork/CompleteProcedureRoportForm",//更改
        //   query: { billID: "", IsPostBack: false },
        // });
        // window.open(routeUrl.path, "_top");
      
      },
     async handleEdit(scope) {
        // 修改
  
        //  let routeUrl = this.$router.push({
        //   path: "/MesPieceWork/CompleteProcedureRoportForm",//更改
        //   query: { billID: scope.row.billID, IsPostBack: false },
        // });
        // window.open(routeUrl.href, "_top");
  
        // this.inputName = row.billID;

        const result = await UpdateForm({ IsPostBack:false,InterID:this.InterID,SavaDate:JSON.stringify(scope.row)});
       this.FormData=result.data1.Table[0];
       this.billIDName=result.billIDName;
      this.dialogType = 'edit'
      this.dialogVisible = true
      this.checkStrictly = true
    
      this.$nextTick(() => {
        const routes = this.generateRoutes(this.EditObj.routes)
        this.$refs.tree.setCheckedNodes(this.generateArr(routes))
        // set checked state of a node not affects its father and child nodes
        this.checkStrictly = false

      })
      this.getDataList();
     
        
      },async handleSave() {
    // 修改
    
  const result = await UpdateForm({ IsPostBack:true,InterID:this.InterID,SavaDate:JSON.stringify(this.FormData)});
   this.FormData=result.data1.Table[0];
   this.billIDName=result.billIDName;
      if (result.code === 20000) {
       
     
        this.$notify({
          title: result.msg,
          dangerouslyUseHTMLString: true,
          message: "",
          type: "success",
        });
        this.getDataList();
      } else {
        this.$notify({
          title: result.msg,
          dangerouslyUseHTMLString: true,
          message: "",
          type: "error",
        });
      }
    
     
      this.getDataList();
    
  },delData({ $index, row }) {
       this.$confirm('删除操作, 是否继续?', '提示', {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
        })
          .then(async () => {
           
             
  
              const result = await DeleteForm({
                InterID:this.InterID,
                SavaDate: JSON.stringify(row),
                IsPostBack: false,
              });
  this.getDataList();
              this.$message({
                type: "success",
                message: result.msg,
              });
            
          })
          .catch((err) => {
            console.error(err);
          });
      }, handrowclick(row)
      {
  
         
           this.billID=row.billID;
  
      },handleOpenClose()
  {
      this.dialogVisible = false
  },handleclose() {
  
  
      if(this.billID!="")
      {
  
   this.$confirm('关单操作, 是否继续? 订单号：'+this.billID, '提示', {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
        })
          .then(async () => {
           
             
  
              const result = await CloseForm({
  
                billID: this.billID,
                types: 1,
                IsPostBack: false,
              });
  this.getDataList();
              this.$message({
                type: "success",
                message: result.msg,
              });
            
          })
          .catch((err) => {
            console.error(err);
          });
      }else
      {
         this.$notify({
              title: "关单操作，请选择数据"+this.billID,
              dangerouslyUseHTMLString: true,
              message: "",
              type: "error",
            });
      }
  
  
      
      },
       
         
    }
  }
  </script>
  
  <style lang="scss" scoped>
  
  .app-container {
    .EditObjs-table {
      margin-top: 30px;
    }
  
    .permission-tree {
      margin-bottom: 5px;
    }
  }
  .searchDialog ::v-deep .el-dialog__header {
    background: #409eff;
  }
  .searchDialog ::v-deep .el-dialog__title {
    color: #fff;
  }
  .searchDialog ::v-deep .el-dialog__headerbtn .el-dialog__close {
    color: #fff;
  }
  </style>